package com.ad.pet.common.structure;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.structure.ui.control.StatusLayout;
import com.ad.pet.common.structure.ui.control.manager.StatusLayoutManager;

import java.util.List;

/**
 * Created by z on.
 * Des:
 * Date: 2017/3/21
 */

public class UICallbackStatusLayoutManager {

    public static boolean checkNull(List ts, StatusLayoutManager statusLayoutManager, boolean isShowEmpty) {
        if (ts == null || ts.isEmpty()) {
            if (isShowEmpty) {
                statusLayoutManager.showEmpty();
            }
            return true;
        }
        statusLayoutManager.showContent();
        return false;
    }

    public static boolean checkNull(List ts, StatusLayoutManager statusLayoutManager) {
        return checkNull(ts, statusLayoutManager, true);
    }

    public static void setAdapter(BaseQuickAdapter adapter, List ts, StatusLayoutManager statusLayoutManager) {
        if (!checkNull(ts, statusLayoutManager)) {
            adapter.setNewData(ts);
        }
    }

    public static void checkRemove(BaseQuickAdapter adapter, int position,
                                   StatusLayoutManager statusLayoutManager) {
        adapter.remove(position);
        if (adapter.getData() == null || adapter.getData().isEmpty()) {
            statusLayoutManager.showEmpty();

        }
    }

    public static void checkEmpty(BaseQuickAdapter adapter, StatusLayoutManager statusLayoutManager) {
        if (adapter.getData() == null || adapter.getData().isEmpty()) {
            statusLayoutManager.showEmpty();
        }
    }

    /**
     * 检查content
     *
     * @param statusLayoutManager
     * @param errorMsg
     * @return true 代表content状态
     */
    public static boolean checkContent(StatusLayoutManager statusLayoutManager, String errorMsg) {
        if (statusLayoutManager.getCurrentLayoutId() != StatusLayout.LAYOUT_CONTENT_ID) {
            statusLayoutManager.showError(errorMsg);
            return false;
        }
        statusLayoutManager.showContent();
        ToastUtil.getToastUtil().showShort(errorMsg);
        return true;
    }
}
